using System;
namespace PingPong.GameEngine.Components
{
	public class Player : IScorable<Player>
	{
		#region Members
		
        /// <summary>
        /// The name.
        /// </summary>
		private Lazy<string> name;
        /// <summary>
        /// The score.
        /// </summary>
        private Lazy<Score> score;
		
		#endregion
			
			
		#region Properties
			
        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
		public string Name
        {
            get
            {
                return this.name.Value;
            }
		}
			
		#endregion
		
		#region Constructors
		
        /// <summary>
        /// Initializes a new instance of the <see cref="PingPong.GameEngine.Components.Player"/> class.
        /// </summary>
		public Player()
		{
			this.name = new Lazy<string>(() => string.Empty);
			this.score = new Lazy<Score>(() => new Score());
		}
		
		#endregion

        #region Methods

        /// <summary>
        /// Sets the name.
        /// </summary>
        /// <returns>
        /// The name.
        /// </returns>
        /// <param name='name'>
        /// Name.
        /// </param>
        public Player SetName(string name)
        {
            this.name = new Lazy<string>(() => name);
            return this;
        }

        #endregion
		
		#region Implementation of IScorable<T>
		
		/// <summary>
        /// Gets the score.
        /// </summary>
        /// <value>
        /// The score.
        /// </value>
        public Score Score
        {
            get
            {
                return this.score.Value;
            }
        }
		
		/// <summary>
        /// Sets the score.
        /// </summary>
        /// <returns>
        /// The score.
        /// </returns>
        /// <param name='score'>
        /// Score.
        /// </param>
        public Player SetScore(Score score)
		{
			if (score == null)
			{
				throw new ArgumentNullException("score");
			}
			
            this.score = new Lazy<Score>(() => score);
            return this;
        }
		
		#endregion
	}
}

